package com.carryduck.boss.controller;

import com.alibaba.fastjson.JSON;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

@Controller
@RequestMapping("/admin")
public class AdminController {

    private Logger logger = LoggerFactory.getLogger(this.getClass());

//    @Autowired
//    private UserAdminService userAdminService;

    @RequestMapping("/index")
    public String index(HttpServletRequest request, Model model) {
//        model.addAttribute("user", (TbAdminUser) request.getSession().getAttribute("user"));
        return "index";
    }

    @RequestMapping("/detail")
    public String detail(HttpServletRequest request, Model model) {
//        model.addAttribute("user", (TbAdminUser) request.getSession().getAttribute("user"));
        return "pages/admin/detail";
    }

    @RequestMapping("/password")
    public String password() {
        return "pages/admin/password";
    }


    /**
     * 获取权限菜单
     *
     * @param request
     * @param response
     * @return
     */
    @GetMapping(value = "/findMenus")
    @ResponseBody
    public Object findMenus(HttpServletRequest request, HttpServletResponse response) {
        Map result = new HashMap<>();
//        List<Node> tree = userAdminService.findMenus(request, response);
//        if (null == tree || tree.size() == 0) {
//            result.put("status", 201);
//            result.put("msg", "获取失败");
//            result.put("data", "");
//        } else {
//            result.put("status", 0);
//            result.put("msg", "ok");
//            result.put("data", tree);
//        }
        return JSON.toJSON(result);
    }

    /**
     * 获取权限菜单
     *
     * @param request
     * @return
     */
    @PostMapping(value = "/modPassword")
    @ResponseBody
    public Object modPassword(String oldPassword, String newPassword, HttpServletRequest request) {
//        Map result = userAdminService.modPassword(oldPassword, newPassword, ((TbAdminUser) request.getSession().getAttribute("user")).getAdminId());
//        return JSON.toJSON(result);
        return JSON.toJSON("占位");
    }

}
